package com.controller.admin;

import com.service.admin.AdminUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class AdminUserController {

  @Autowired AdminUserService adminUserService;
  /**
   * 获取所有用户数量
   *
   * @return 所有用户数量
   */
  @PostMapping("admin/getAllUserCount")
  public String getAllUserCount() {
    int count = adminUserService.getAllUserCount();
    return String.valueOf(count);
  }

  /**
   * 获取所有用户
   *
   * @param pageSize 页大小
   * @param pageIndex 页索引
   * @return 用户列表
   */
  @PostMapping("admin/getAllUsers")
  public List<Map<String, Object>> getAllUsers(
      @RequestParam("pageSize") int pageSize,
      @RequestParam("pageIndex") int pageIndex,
      String userId) {
    return adminUserService.getAllUsers(pageSize, pageIndex, userId);
  }
  /**
   * 获取用户的商品出售权限
   *
   * @param userId 用户编号
   * @return 用户商品违规次数
   */
  @PostMapping("admin/getUserGoodPermission")
  public Map<String, Object> getUserGoodPermission(@RequestParam("userId") String userId) {
    return adminUserService.getUserGoodPermission(userId);
  }

  /**
   * 获取用户的评论权限
   *
   * @param userId 用户编号
   * @return 评论被举报成功次数、禁言至
   */
  @PostMapping("admin/getUserCommentPermission")
  public Map<String, Object> getUserCommentPermission(@RequestParam("userId") String userId) {
    return adminUserService.getUserCommentPermission(userId);
  }
}
